<template>
<h1>员工列表练习</h1>
  员工姓名：<input type="text" placeholder="请输入员工姓名" v-model="user.name">
  员工工资：<input type="text" placeholder="请输入员工工资" v-model="user.say">
  员工岗位：<input type="text" placeholder="请输入员工岗位" v-model="user.job">
  <button @click="add">点击添加</button>
  <hr>
  <table border="1">
    <tr>
      <th>员工编号</th>
      <th>员工姓名</th>
      <th>员工工资</th>
      <th>员工岗位</th>
    </tr>
    <tr v-for="(u,index) in arr">
      <td>{{index+1}}</td>
      <td>{{u.name}}</td>
      <td>{{u.say}}</td>
      <td>{{u.job}}</td>
    </tr>

  </table>

</template>



<script setup>

 import {ref} from "vue";


 const user = ref({name:'', say:'', job:''});

 const arr= ref([]);

 const add = ()=>{
   if (user.value.name.trim()=='' || user.value.say.trim()=='' || user.value.job.trim()==''){
     alert('请填写完整的员工信息');
     return;
   }
  arr.value.push(user.value);
   console.log(arr.value);
 user.value = {name:'',say:'',job:''};
 }

</script>


<style scoped>

</style>